""" URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.urls import path
from django.contrib.auth.decorators import login_required
from .views import (DeployCreateView, DeployListView, DeployUpdateView, DeployDetailView,
                    jenkins_build, jenkins_status, update_deploypool_jenkins)
from .upload_views import DeployVersionUploadView, fileupload
from .deploy_views import PublishView, DeployView, OperateView, OperateAppView, HistoryView, deploy_cmd
from .report_views import get_deploy_count, get_app_deploy_count, DeployCountView, AppDeployCountView


app_name = 'deploy'

urlpatterns = [
    path('create/', login_required(DeployCreateView.as_view()), name='create'),
    path('list/', login_required(DeployListView.as_view()), name='list'),
    path('edit/<slug:pk>/', login_required(DeployUpdateView.as_view()), name='edit'),
    path('view/<slug:pk>/', login_required(DeployDetailView.as_view()), name='detail'),
    path('jenkins_build/', jenkins_build, name='jenkins_build'),
    path('jenkins_status/', jenkins_status, name='jenkins_status'),
    path('update_deploypool_jenkins/', update_deploypool_jenkins, name='update_deploypool_jenkins'),
]

# upload_views
urlpatterns += [
    path('upload/', login_required(DeployVersionUploadView.as_view()), name='upload'),
    path('file_upload/', fileupload, name='file-upload'),
]

# deploy_views
urlpatterns += [
    path('publish/', login_required(PublishView.as_view()), name='publish'),
    path('deploy/<slug:app_name>/<slug:deploy_version>/<slug:env>/', login_required(DeployView.as_view()), name='deploy'),
    path('deploy-cmd/', deploy_cmd, name='deploy-cmd'),
    path('operate/', login_required(OperateView.as_view()), name='operate'),
    path('operate/<slug:app_name>/<slug:env>/', login_required(OperateAppView.as_view()), name='operate_app'),
    path('history/', login_required(HistoryView.as_view()), name='history'),
]


# report_views
urlpatterns += [
    path('get_deploy_count/', get_deploy_count, name='get_deploy_count'),
    path('get_app_deploy_count/', get_app_deploy_count, name='get_app_deploy_count'),
    path('deploy_count/', DeployCountView.as_view(), name='deploy_count'),
    path('app_deploy_count/', AppDeployCountView.as_view(), name='app_deploy_count'),
]
